<style lang="less">
    @import './login.less';
</style>

<template>
    <div class="login">
        <div class="login-con">
            <Card icon="log-in" title="欢迎登录" :bordered="false">
                <div class="form-con">
                    <login-form @on-success-valid="handleSubmit"></login-form>
                    <p class="login-tip">{{ msg }}</p>
                </div>
            </Card>
        </div>
    </div>
</template>

<script>
    import LoginForm from '../../components/login-form';
    import {mapActions} from 'vuex';
    import {Message} from 'iview';

    export default {
        components: {
            LoginForm
        },
        methods: {
            ...mapActions([
                'handleLogin',
                'getUserInfo'
            ]),
            handleSubmit({loginAccount, password}) {
                this.handleLogin({loginAccount, password}).then(res => {
                    if (this.token != '') {
                        this.getUserInfo().then(res => {
                            this.$router.push({
                                name: 'home'
                            })
                        })
                    }else{
                        Message.error('账号密码错误！');
                    }
                })
            }
        },
        computed: {
            msg() {
                return this.$store.getters.msg;
            },
            token() {
                return this.$store.getters.token;
            }
        }
    }
</script>

<style>

</style>
